//
//  HMViewController.m
//  HMTabBarContentView
//
//  Created by wy46817@gmail.com on 09/11/2017.
//  Copyright (c) 2017 wy46817@gmail.com. All rights reserved.
//

#import "HMViewController.h"
#import <HMTabBarContentView/HMTabBarContentView.h>
#import <Masonry/Masonry.h>

@interface HMViewController () <HMTabBarContentViewDelegate,HMTabBarContentViewDataSource>

@property (strong ,nonatomic) HMTabBarContentView *tabBarContentView ;

@end

@implementation HMViewController{
    NSInteger _count;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _count = arc4random_uniform(6) + 2;

    self.tabBarContentView = [HMTabBarContentView new];

    [self.view addSubview:self.tabBarContentView];

    [self.tabBarContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(320 , 400));
    }];

    self.tabBarContentView.delegate = self;
    self.tabBarContentView.datasource = self;

    [self.tabBarContentView reloadData];

}

#pragma mark - HMTabBarContentViewDataSource - 
- (NSInteger)numberOfItemsInTabBarContentView:(HMTabBarContentView *)tabBarContentView{
    //提供内容选项个数
    return  _count;
}

- (NSString *)tabBarContentView:(HMTabBarContentView *)tabBarContentView titleAtItemIndex:(NSInteger)index{
    //提供标题
    return [NSString stringWithFormat:@"item : %zd",index];
}

- (UIView *)tabBarContentView:(HMTabBarContentView *)tabBarContentView contentViewAtItemIndex:(NSInteger)index{
    //提供选项内容
    UILabel *label = [UILabel new];

    label.textAlignment =  NSTextAlignmentCenter;
    label.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0];
//    label.backgroundColor = [UIColor redColor];
    label.text = [NSString stringWithFormat:@"item : %zd",index];

    return label;
}

#pragma mark - HMTabBarContentViewDelegate - 
- (CGFloat)tabBarHeightInTabBarContentView:(HMTabBarContentView *)tabBarContentView{
    //提供导航条高度
    return 30;
}

- (UIView *)heightLightTabBarItemViewInTabBarContentView:(HMTabBarContentView *)tabBarContentView{
    //提供高亮的选中导航条选项视图
    UIView *view = [UIView new];

    UIView *line = [UIView new];
    line.backgroundColor = [UIColor orangeColor];

    [view addSubview:line];

    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(view);
        make.height.mas_equalTo(2);
    }];

    return view;
}

- (void)tabBarContentView:(HMTabBarContentView *)tabBarContentView didSelectedAtIndex:(NSInteger)index{
    NSLog(@"被选中:%zd",index);
}



@end
